<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js"> </script>
</head>

<body>
  <div id="app">
    <button id="test">getAuthCode</button>
  </div>
</body>
<script type="text/javascript">
  document.querySelector('#test').addEventListener('click', function () {
    ap.getAuthCode({
      appId: '2021000116682174',
      scopes: ['auth_user'],
    }, function (res) {
      if (res.error) {
        ap.alert(res.authCode);
        return
      }
      // ap.alert(JSON.stringify(res.authCode));
      fetch("https://chengsancai.xyz:1234/getUserToken?authCode=" + res.authCode, {
        method: "POST",
        body: {
          authCode: res.authCode
        },
        headers: {
          'Content-Type': 'application/x-www-form-urlencoded'
        }
      }).then(res => {
        alert(res);
        ap.alert(JSON.stringify(res));
      })
    });
  });
</script>

</html>